import 'package:flutter/material.dart';
import 'package:music_app/widget/my_cached_network_image.dart';

class PlaylistCover extends StatelessWidget {
  final String imageUrl;
  final String title;
  final VoidCallback onTap;
  final VoidCallback onPlayTap;
  final double width;
  final double height;

  const PlaylistCover({
    super.key,
    required this.imageUrl,
    required this.title,
    required this.onTap,
    required this.onPlayTap,
    this.width = 100,
    this.height = 100,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap, // 整体点击
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Stack(
            children: [
              // 封面图片
              ClipRRect(
                borderRadius: BorderRadius.circular(12),
                child: MyCachedNetworkImage(
                  imageUrl: imageUrl,
                  width: width,
                  height: height,
                  x: 400,
                  y: 400,
                ),
              ),
              // 播放按钮
              Positioned(
                right: 6,
                bottom: 6,
                child: GestureDetector(
                  onTap: onPlayTap, // 播放点击
                  child: Container(
                    padding: const EdgeInsets.all(6),
                    decoration: const BoxDecoration(
                      color: Colors.black54,
                      shape: BoxShape.circle,
                    ),
                    child: const Icon(
                      Icons.play_arrow,
                      color: Colors.white,
                      size: 12,
                    ),
                  ),
                ),
              ),
            ],
          ),
          const SizedBox(height: 8),
          Text(
            title,
            maxLines: 2,
            overflow: TextOverflow.ellipsis,
            style: const TextStyle(fontSize: 14, color: Colors.black),
          ),
        ],
      ),
    );
  }
}
